import api from '../utils/api';

// 健康数据类型定义
export interface HealthData {
  id: number;
  userId: number;
  bloodPressure: string; // 血压，格式：收缩压/舒张压
  heartRate: number; // 心率
  bloodSugar: number; // 血糖
  weight: number; // 体重
  temperature: number; // 体温
  recordTime: string; // 记录时间
  status: number; // 1-正常，2-异常
  createTime: string;
  updateTime: string;
}

// 健康数据服务类
class HealthDataService {
  // 保存健康数据
  async saveHealthData(params: Omit<HealthData, 'id' | 'status' | 'createTime' | 'updateTime'>): Promise<HealthData> {
    return await api.post('/health/save', params);
  }

  // 批量保存健康数据
  async batchSaveHealthData(dataList: Omit<HealthData, 'id' | 'status' | 'createTime' | 'updateTime'>[]): Promise<void> {
    return await api.post('/health/batch-save', dataList);
  }

  // 获取用户最新健康数据
  async getLatestHealthData(userId: number): Promise<HealthData> {
    return await api.get(`/health/latest/${userId}`);
  }

  // 获取健康数据历史记录
  async getHealthDataHistory(
    userId: number,
    startTime: string,
    endTime: string
  ): Promise<HealthData[]> {
    return await api.get('/health/history', {
      userId,
      startTime,
      endTime
    });
  }

  // 获取异常健康数据
  async getAbnormalHealthData(userId: number): Promise<HealthData[]> {
    return await api.get(`/health/abnormal/${userId}`);
  }

  // 获取健康数据统计信息
  async getHealthDataStatistics(userId: number, days: number = 7): Promise<any> {
    return await api.get('/health/statistics', {
      userId,
      days
    });
  }
}

export default new HealthDataService();